#ifndef FORM_YK_WZRK_H
#define FORM_YK_WZRK_H

#include <QWidget>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include <QSqlRecord>
#include <QTableView>
#include <QRegularExpression>
#include <QPrinter>
#include <QPainter>
#include <QTimer>
#include <QCompleter>

namespace Ui {
class Form_yk_wzrk;
}

class Form_yk_wzrk : public QWidget
{
    Q_OBJECT

public:
    explicit Form_yk_wzrk(QWidget *parent = nullptr);
    ~Form_yk_wzrk();

    void closeEvent(QCloseEvent *event);

signals:
        void destroyW( QString );

private slots:

        void from_input_check(QString sour, QString dest);

        void search_checked(QString sour, QString dest);

        bool check_input(QSqlRecord rcd, QMap<QString,QString> pa, QString); //
        void mat_kind_manipulate( QString name, QString code,QString valid );
        void com_dict_manipulate(QString type, QString name,
                                QString code,QString valid );
        void change_lock_status(QString type, bool status);//锁定和解除录入时的库房
        void calc_amount(); //计算项目金额
        bool checkStatus(QString);  //检验数据合理性
        void showList();//显示已经未保存数据列表

        bool ins_input(QSqlRecord, QMap<QString,QString>);
        bool ins_output(QSqlRecord, QMap<QString,QString>);
        bool ins_storage(QSqlRecord, QMap<QString,QString>);
        void search_item(QString key,    //检索关键字
                         QSqlQueryModel *md,  // sqlmodel
                         QTableView *tv,      //显示列表
                         QString mode);  //出入模式

        QRectF getRealPosition(int row, int col);   //通过表格行列计算打印位置
        void printPageBase();
        void printCellItem(QString item_name, QString item_value, int pos);
        void listPrintItem(QString);    //根据 list code 显示单据内容
        void item_info_clear(); //项目维护状态清除
        bool item_check();  //校验项目维护内容
        void timer_fac_changed_out();
        void generate_specs();  //生成规格

        void item_selected(const QModelIndex);

        void on_pbExit_clicked();

        void on_pbFresh_clicked();

        void on_tvList_clicked(const QModelIndex &index);

        void on_pbSave0_clicked();

        void on_pbSearch_clicked();

        void on_pb_new_company_clicked();

        void on_leKey_returnPressed();

        void on_tvSource_r_clicked(const QModelIndex &index);

        void on_tvSource_r_doubleClicked(const QModelIndex &index);

        void on_leRksl_textChanged(const QString &arg1);

        void on_leGrjg_textChanged(const QString &arg1);

        void on_pbAdd_clicked();

        void on_pbSave_clicked();

        void on_pbRemove_clicked();

        void on_pbSearch_3_clicked();

        void on_lePh_returnPressed();

        void on_leScrq_returnPressed();

        void on_leXq_returnPressed();

        void on_pbSearch_2_clicked();

        void on_leKey_2_returnPressed();

        void on_leKey_3_returnPressed();

        void on_pbAdd_2_clicked();

        void on_tvSource_c_clicked(const QModelIndex &index);

        void on_tvSource_c_doubleClicked(const QModelIndex &index);

        void on_leRksl_2_textChanged(const QString &arg1);

        void on_pbRemove_2_clicked();

        void on_pbSave_2_clicked();

        void on_cbbMode_r_currentTextChanged(const QString &arg1);

        void on_cbbReceiveDept_currentIndexChanged(const QString &arg1);

        void on_leRksl_2_returnPressed();

        void on_leRksl_returnPressed();

        void on_pbPrintOut_clicked();

        void on_prPrintSearch_clicked();

        void on_tvInList_clicked(const QModelIndex &index);

        void on_tvInList_doubleClicked(const QModelIndex &index);

        void on_tvOutList_clicked(const QModelIndex &index);

        void on_tvOutList_doubleClicked(const QModelIndex &index);

        void on_lwToPrint_doubleClicked(const QModelIndex &index);

        void on_leFph_returnPressed();

        void on_leFprq_returnPressed();

        void on_leTax_textChanged(const QString &arg1);

        void on_tvDest_r_clicked(const QModelIndex &index);

        void on_tvDest_r_doubleClicked(const QModelIndex &index);

        void on_pbNewDrug_clicked();

        void on_tv_config_clicked(const QModelIndex &index);

        void on_tv_config_doubleClicked(const QModelIndex &index);

        void on_pbAdd_4_clicked();

        void on_cbb_producer_code_editTextChanged(const QString &arg1);

        void on_cbb_min_unit_currentTextChanged(const QString &arg1);

        void on_le_pack_qty_textChanged(const QString &arg1);

        void on_cbb_pack_unit_currentTextChanged(const QString &arg1);

        void on_le_item_name_textChanged(const QString &arg1);

        void on_pb_status_unlock_in_clicked();

        void on_pb_unlock_status_out_clicked();

        void dict_clicked();

        void on_rb_kind_clicked();

        void on_rb_unit_pack_clicked();

        void on_rb_unit_min_clicked();

        void on_tabWidget_currentChanged(int index);

        void on_tv_dic_value_clicked(const QModelIndex &index);

        void on_tv_dic_value_doubleClicked(const QModelIndex &index);

        void on_pb_save_dict_clicked();

        void on_pb_fresh_dict_clicked();

        void on_cbbMode_c_currentTextChanged(const QString &arg1);

private:
    Ui::Form_yk_wzrk *ui;

    QSqlQueryModel *md, *mdrs, *mdrd, *mdcs, *mdcd ;
    QSqlQueryModel *md_dict;//

    QSqlQueryModel *md_p_in, *md_p_out, *md_p_brw;  //打印相关

    QSqlQuery *qrm, *qro, *qrmt, *qrmp, *qrot;
    QString groups, drugCode;
    //科室、代码  ，  出入模式、代码,  经销公司、代码， 生产厂、代码， 门诊用药科室、代码
    QString store_depts, mode_code_r, mode_code_c,
            company_codes, producer_codes, drug_consume_depts;
    //药品包装单位, 最小单位, 剂量单位，系统类别， 药品属性, 药品类别, 药品等级
    QString pack_units, min_units, dose_units, mat_kind, drug_quality, drug_type, item_grade;
    //费用类别, 药品剂型, 医师职级
    QString fee_code, dose_models, duty_constrains;
    QString sq;
    QMap<QString,QString> item_detail;  //当前选中的项目内容
    QRegularExpression rg_num,rg_date; //正则

    QPrinter *prt;      //打印机
    QPainter *pnt;
    double xPos,yPos;      //页面坐标偏移
    float ptScale;  //for printer, mm to point covnert.
    float margin;   //单元格边界缩进
    QStringList grid_row, grid_col;  //表格打印区域分隔

    bool initialFinished; //界面初始化是否完成
    bool is_new_drug;   //新增药品
    bool is_new_fac;   //新增供应关系
    QTimer *timer_fac_changed;

    QCompleter *comp;//下拉列表自动补全

};

#endif // FORM_YK_WZRK_H
